package com.example.bookinfo;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.TextView;

public class BookDetailActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_book_detail);

        // 设置Toolbar
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        // 显示返回按钮
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowHomeEnabled(true);
            getSupportActionBar().setTitle(""); // 清空默认标题
        }

        // 获取传递过来的数据
        String title = getIntent().getStringExtra("title");
        String author = getIntent().getStringExtra("author");
        String description = getIntent().getStringExtra("description");

        // 初始化视图
        TextView tvTitle = findViewById(R.id.tvDetailTitle);
        TextView tvAuthor = findViewById(R.id.tvDetailAuthor);
        TextView tvDescription = findViewById(R.id.tvDetailDescription);

        // 设置数据
        tvTitle.setText(title);
        tvAuthor.setText("作者: " + author);
        tvDescription.setText(description);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // 处理返回按钮点击事件
        if (item.getItemId() == android.R.id.home) {
            onBackPressed();  // 调用返回方法
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        // 添加返回动画
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    }
}